﻿Ext.define('HMSDesktop.ChangePwd', {
    extend: 'Ext.window.Window',
    title: '修改登录密码',
    width: 350,
    resizable: false,
    draggable: true,
    layout: 'fit',
    plain: false,
    modal: true,
    border: false,
    iconCls: 'lock',

    initComponent: function () {
        var me = this;
        me.form = me.createForm();
        me.items = [me.form];
        me.buttons = [{
            text: '提    交',
            handler: me.onSubmit,
            scale: 'medium',
            width: 80,
            height: 35,
            icon: "/Admin/style/24Icons/clean.png",
            scope: me
        }, {
            text: '重    置',
            handler: me.onReset,
            scale: 'medium',
            width: 80,
            height: 35,
            icon: "/Admin/style/24Icons/new-view-refresh.png",
            scope: me
        }, {
            text: '退    出',
            handler: function () {
                this.close();
            },
            scale: 'medium',
            width: 80,
            height: 35,
            icon: "/Admin/style/24Icons/Close2.png",
            scope: me
        }];
        me.callParent();

    },
    createForm: function () {
        var me = this;
        var form = new Ext.form.FormPanel({
            bodyStyle: "padding: 20px 50px",
            border: false,
            frame: true,
            defaults: {
                width: 220,
                labelWidth: 60,
                labelAlign: 'right'
            },
            items: [{
                xtype: 'textfield',
                inputType: 'password',
                fieldLabel: '旧密码',
                name: 'oldPwd',
                allowBlank: false
            }, {
                xtype: 'textfield',
                inputType: 'password',
                name: 'newPwd',
                fieldLabel: '新密码',
                allowBlank: false,
                vtype: 'password',
                initialPassField: 'newConfirmPwd'
            }, {
                xtype: 'textfield',
                inputType: 'password',
                name: 'newConfirmPwd',
                fieldLabel: '确认密码',
                allowBlank: false,
                vtype: 'password',
                initialPassField: 'newPwd'
            }]
        });
        return form;
    },
    onSubmit: function () {
        var form = this.form.form;
        if (form.isValid()) {
            form.submit({
                scope: this,
                params: { s_method: 'save', s_action: 'EditPassword' },
                url: 'facade.axd',
                success: function (form, action) {
                    //ShowInfoMsg('系统提示', '成功修改密码！下次登录时请使用新密码！');
                    Ext.create('Kwan.ex.PopupWin', {
                        title: '系统提示',
                        html: '成功修改密码！下次登录时请使用新密码！'
                    }).show();
                    this.close();
                },
                failure: function () {
                    ShowWarningMsg('修改失败！', '请检查各输入项的正确性！');
                }
            });
        }
    },
    onReset: function () {
        this.form.form.reset();
    }
});